package com.ssm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ssm.dao.EmployeeMapper;
import com.ssm.entity.Dept;
import com.ssm.entity.Employee;
import com.ssm.entity.EmployeeVo;
import com.ssm.entity.query.EmployeeQueryVo;
import com.ssm.service.EmployeeService;
import com.ssm.utils.Page;
import com.ssm.utils.Search;
import com.ssm.utils.Condition;

@Service
public class EmployeeServiceImpl implements EmployeeService{

	@Autowired
	private EmployeeMapper employeeDao;
	
	/**
	 * 加载员工列表-分页、多条件组合
	 * @param eqv
	 * @return
	 */
	@Override
	public Page<EmployeeVo> loadEmployeeByPage(EmployeeQueryVo eqv) {
//		List<Condition> list = new ArrayList<Condition>();
//		if(eqv.getSearchEmpName() != null && !"".equals(eqv.getSearchEmpName())) {
//			list.add(new Condition("and", "e.empName", "like", "'%"+eqv.getSearchEmpName()+"%'"));
//		}
//		if(eqv.getSearchPhone() != null && !"".equals(eqv.getSearchPhone())) {
//			list.add(new Condition("and", "e.phone", "like", "'%"+eqv.getSearchPhone()+"%'"));
//		}
//		if(null != eqv.getSearchDeptid() && eqv.getSearchDeptid() > 0) {
//			list.add(new Condition("and", "e.deptid", "=", eqv.getSearchDeptid()));
//		}
//		if(null != eqv.getSearchGender() && eqv.getSearchGender() > 0) {
//			list.add(new Condition("and", "e.gender", "=", eqv.getSearchGender()));
//		}
//		if(null != eqv.getSearchAge1() && eqv.getSearchAge1() > 0) {
//			list.add(new Condition("and", "e.age", "&gt;=", eqv.getSearchAge1()));
//		}
//		if(null != eqv.getSearchAge2() && eqv.getSearchAge2() > 0) {
//			list.add(new Condition("and", "e.age", "&lt;=", eqv.getSearchAge2()));
//		}
//		if(eqv.getSearchEntryDate1() != null && !"".equals(eqv.getSearchEntryDate1())) {
//			list.add(new Condition("and", "e.entryDate", "&gt;=", eqv.getSearchEntryDate1()));
//		}
//		if(eqv.getSearchEntryDate2() != null && !"".equals(eqv.getSearchEntryDate2())) {
//			list.add(new Condition("and", "e.deptid", "&lt;=", eqv.getSearchEntryDate2()));
//		}
//		Search search = new Search(list, eqv.getBeginIndex(), eqv.getPageSize());
//		List<EmployeeVo> rows = employeeDao.loadEmployeeByPage2(search);
//		long total = employeeDao.loadEmployeeCount2(search);
		List<EmployeeVo> rows = employeeDao.loadEmployeeByPage(eqv);
		long total = employeeDao.loadEmployeeCount(eqv);
		return new Page<EmployeeVo>(eqv.getPageNo(), eqv.getPageSize(), total, rows);
	}

	/**
	 * 通过员工id加载一个员工对象
	 * @param empid
	 * @return
	 */
	@Override
	public Employee loadEmployeeById(int empid) {
		return employeeDao.loadEmployeeById(empid);
	}

	/**
	 * 加载所有部门
	 * @return
	 */
	@Override
	public List<Dept> loadAllDept() {
		List<Dept> list = employeeDao.loadAllDept();
		list.add(0, new Dept(-1, "--请选择部门--"));
		return list;
	}


}
